package com.test.pack1.demo.base2_1;


/**
 * Created by dws on 2017/12/14.
 * 选择排序
 */
public class Selection {

    public static void sort(Comparable[] a){

        int N = a.length;

        for (int i = 0; i < N; i++) {
            int min = i;
            for (int j=i+1;j<N;j++){
                if(less(a[j],a[min]))min=j;
            }
            exch(a,i,min);
        }
    }

    public static void exch(Comparable[] a,int minIndex,int smallerIndex){
        Comparable t = a[smallerIndex];
        a[smallerIndex] = a[minIndex];
        a[minIndex] = t;
    }
    public static boolean less(Comparable v,Comparable w){
        return v.compareTo(w)<0;
    }

}
